<?php
// +----------------------------------------------------------------------
// | Ghome/Admin/Controller/ZCEController
// +----------------------------------------------------------------------
// | Author: alex <gt199899@gmail.com>
// +----------------------------------------------------------------------
// | Version: 2014-06-24
// +----------------------------------------------------------------------
// | Copyright: Perfect Is Shit
// +----------------------------------------------------------------------
namespace Admin\Controller;
class ZCEController extends InitController{
	
	public $zceTextPath;
	
	/**
	 * init
	 * @access public
	 * @author alex
	 * @version 2014-06-26
	 * @copyright Perfect Is Shit
	 */
	public function _initialize(){
		parent::_initialize();
		$this->zceTextPath = C('PHY_PATH.PUBLIC') . "/ZCE";
	}
	
	/**
	 * show outline
	 * @access public
	 * @author alex
	 * @version 2014-06-26
	 * @copyright Perfect Is Shit
	 */
	public function outline(){
		$this->display();
	}
	
	/**
	 * 获取zce大纲信息
	 * @access public
	 * @author alex
	 * @version 20140410
	 * @copyright Perfect Is Shit
	 */
	public function zceOutline(){
		$outline = file_get_contents($this->zceTextPath . '/outline.inc');
		$outline = json_decode($outline, true);
		$eaui_treegrid_data = array();
		foreach($outline as $key=>$value){
			$level1_data['name'] = $key;
			$level1_data['id'] = md5($key.rand(111,999));
			$level1_data['state'] = 'closed';
			$level1_data['phyadd'] = '-';
			$level1_data['iconCls'] = 'icon-blank';
			if(!is_array($value)){
				continue;
			}
			foreach($value as $k=>$v){
				$level2_data['name'] = $k;
				$level2_data['id'] = md5($k.rand(111,999));
				$level2_data['phyadd'] = '-';
				$level2_data['iconCls'] = 'icon-blank';
				if(!is_array($v) || empty($v)){
					$level1_data['children'][] = $level2_data;
					continue;
				}
				$level2_data['state'] = 'closed';
				foreach($v as $m=>$n){
					$level3_data['name'] = $n;
					$level3_data['id'] = md5($n.rand(111,999));
					$level3_data['phyadd'] = '-';
					$level3_data['iconCls'] = 'icon-blank';
					$level2_data['children'][] = $level3_data;
				}
				$level1_data['children'][] = $level2_data;
				unset($level3_data, $level2_data);
			}
			$eaui_treegrid_data[] = $level1_data;
			unset($level1_data);
		}
		unset($key, $value, $k, $v, $m, $n);
		echo json_encode($eaui_treegrid_data);
	}
	
}